package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhPartsSales;
import com.ruoyi.zsyh.service.IZsyhPartsSalesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品销量统计Controller
 * 
 * @author yuexl
 * @date 2021-12-29
 */
@Controller
@RequestMapping("/zsyh/partsSales")
public class ZsyhPartsSalesController extends BaseController
{
    private String prefix = "zsyh/partsSales";

    @Autowired
    private IZsyhPartsSalesService zsyhPartsSalesService;

    @RequiresPermissions("zsyh:partsSales:view")
    @GetMapping()
    public String partsSales()
    {
        return prefix + "/partsSales";
    }

    /**
     * 查询产品销量统计列表
     */
    @RequiresPermissions("zsyh:partsSales:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhPartsSales zsyhPartsSales)
    {
        startPage();
        List<ZsyhPartsSales> list = zsyhPartsSalesService.selectZsyhPartsSalesList(zsyhPartsSales);
        return getDataTable(list);
    }

    /**
     * 导出产品销量统计列表
     */
    @RequiresPermissions("zsyh:partsSales:export")
    @Log(title = "产品销量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhPartsSales zsyhPartsSales)
    {
        List<ZsyhPartsSales> list = zsyhPartsSalesService.selectZsyhPartsSalesList(zsyhPartsSales);
        ExcelUtil<ZsyhPartsSales> util = new ExcelUtil<ZsyhPartsSales>(ZsyhPartsSales.class);
        return util.exportExcel(list, "产品销量统计数据");
    }

    /**
     * 新增产品销量统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品销量统计
     */
    @RequiresPermissions("zsyh:partsSales:add")
    @Log(title = "产品销量统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhPartsSales zsyhPartsSales)
    {
        return toAjax(zsyhPartsSalesService.insertZsyhPartsSales(zsyhPartsSales));
    }

    /**
     * 修改产品销量统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhPartsSales zsyhPartsSales = zsyhPartsSalesService.selectZsyhPartsSalesById(id);
        mmap.put("zsyhPartsSales", zsyhPartsSales);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品销量统计
     */
    @RequiresPermissions("zsyh:partsSales:edit")
    @Log(title = "产品销量统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhPartsSales zsyhPartsSales)
    {
        return toAjax(zsyhPartsSalesService.updateZsyhPartsSales(zsyhPartsSales));
    }

    /**
     * 删除产品销量统计
     */
    @RequiresPermissions("zsyh:partsSales:remove")
    @Log(title = "产品销量统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhPartsSalesService.deleteZsyhPartsSalesByIds(ids));
    }

    /**
     * 查看销量统计
     */
    @GetMapping("/viewSales")
    public String viewSales(String attributeId,int periodYear,int periodMonth, ModelMap mmap)
    {
        mmap.put("attributeId", attributeId);
        mmap.put("periodYear", periodYear);
        mmap.put("periodMonth", periodMonth);
        return prefix + "/viewSales";
    }
}
